﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

namespace WebApplication2
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }

        public void bind()
        {
            this.GridView1.DataSource = teacherinfoBLL.getall(this.tb_name.Text);
            this.GridView1.DataBind();

        }
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Command(object sender, CommandEventArgs e)
        {
            var id = Convert.ToInt32(e.CommandArgument.ToString());
            int num = teacherinfoBLL.Delete(id);
            if (num > 0)
            {
                Response.Write("<script>alert('删除成功')</script>");
                bind();
            }
            else
            {
                Response.Write("<script>alert('删除失败')</script>");
            }
        }
        //添加
        protected void btn_add_Click(object sender, EventArgs e)
        {
            Response.Redirect("addteacher.aspx");
        }

        //查询
        protected void Button2_Click(object sender, EventArgs e)
        {
            bind();
        }

        //跳转到修改教师信息页面
        protected void btn_edit_Command(object sender, CommandEventArgs e)
        {
            int tno = Convert.ToInt32(e.CommandArgument.ToString());
            Response.Redirect("updateteacher.aspx?tno=" + tno);
        }
    }
}